<?php
include 'inner/init.php';
include 'includes/overall/header.php';

if (empty($_POST) === false ) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    if (empty($username) === true || empty($password) === true) {
        $errors[] = 'You need to enter a username and password!';
    } else if(user_exists($username) === false) {
        $errors[] = 'Username does not exist! Have you registered?';
    }  else {
        $login = login($username, $password);
        if ($login === false) {
            $errors[] = 'Username/Password is incorrect! Try again..';
        } else {
            $_SESSION['user_id'] = $login;
            header('Location: index.php');
            exit();
        }
    }
    print_r($errors);
}
include 'includes/overall/footer.php';
?>